package com.beyondsoft.users.controller;

import com.beyondsoft.users.service.IUsersService;

import com.beyondsoft.common.core.model.Users;
import com.beyondsoft.common.core.model.vo.UsersSearchVO;
import com.beyondsoft.common.core.model.vo.UsersVO;
import com.beyondsoft.common.core.model.dto.UsersDTO;
import com.beyondsoft.common.core.util.R;
import com.beyondsoft.common.core.util.PageBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RefreshScope
@Api(tags = "Users管理模块")
@RequestMapping("/users")
public class UsersController {

    @Autowired
    private IUsersService usersService;

    @ApiOperation(value = "获取Users列表(分页)", notes = "获取Users列表(分页)")
    @GetMapping
    public R<PageBean<UsersDTO>> page(@ModelAttribute UsersSearchVO usersSearchVO) {
        // 获取Users列表
        return new R<>(usersService.page(usersSearchVO));
    }

    @ApiOperation(value = "获取Users列表", notes = "获取Users列表")
    @GetMapping("/findList")
    public R<List<Users>> findList(@ModelAttribute Users users) {
        // 获取Users列表
        return new R<>(usersService.find(users));
    }

    @ApiOperation(value = "获取单个Users", notes = "获取Users信息")
    @GetMapping(value = "/{id}")
    public R<UsersDTO> usersOne(@ApiParam(value = "id", required = true) @PathVariable(value = "id", required = true) Long id) {
        // 获取单个Users
        return new R<>(usersService.findOne(id));
    }

    @ApiOperation(value = "新增Users", notes = "新增Users")
    @PostMapping
    public R insert(@RequestBody UsersVO usersVO) {
        // 新增Users
        usersService.insert(usersVO);
        return new R<>();
    }

    @ApiOperation(value = "编辑Users", notes = "编辑Users")
    @PutMapping
    public R update(@RequestBody UsersVO usersVO) {
        // 编辑Users
        usersService.update(usersVO);
        return new R<>();
    }

    @ApiOperation(value = "删除Users", notes = "删除Users")
    @DeleteMapping(value = "/{id}")
    public R delete(@ApiParam(value = "id", required = true) @PathVariable(value = "id", required = true) Long id) {
		// 删除
		usersService.delete(id);
		return new R<>();
    }

}
